set more 1
clear

pause off 

capture log close

local date : di %td_CY-N-D date("$S_DATE", "DMY")

global dir_tab_out     "../outputs"

global dir_data_in     "out_files"
global dir_work_out    "out_figs" 

******************************************************************
******************************************************************
use $dir_data_in/sim_model_part1, clear

gen hgc = educ 


	gen college = (hgc >= 13)
	gen hsd = (hgc < 12)
	gen college1_dq0 = (college==1 & dq == 0)
	gen college0_dq1 = (college==0 & dq == 1)	
	gen hsd1_dq1 = (hsd == 1 & dq == 1)
			
	foreach num of numlist 30 15 {
	
	  	capture matrix drop diff_elife_a`num'
		
		
		reg elife dq if age == `num' 
	  	matrix b = e(b)
	  	matrix v = e(V) 
	  	matrix b_se = [ -b[1,1] \ ( sqrt(v[1,1]) ) ]
	  	
	  	matrix diff_elife_a`num'   = [nullmat(diff_elife_a`num'), b_se ]



		reg elife dq if age == `num' & ( addiction == `num'-15 | addiction == 0 )
	  	matrix b = e(b)
	  	matrix v = e(V) 
	  	matrix b_se = [ -b[1,1] \ ( sqrt(v[1,1]) ) ]
	  	** "Always_Smoking" 
*	  	matrix diff_elife_a`num'   = [nullmat(diff_elife_a`num'), b_se ]


*		reg elife college if age == `num'  & (college == 1 | hsd == 1)
		reg elife college if age == `num'  
	  	matrix b = e(b)
	  	matrix v = e(V) 
	  	matrix b_se = [ b[1,1] \ ( sqrt(v[1,1]) ) ]
	  	
	  	matrix diff_elife_a`num'   = [nullmat(diff_elife_a`num'), b_se ]

*		reg elife college1_dq0 if age == `num'  & ( college1_dq0 == 1 |  hsd1_dq1 == 1 )		

		reg elife college1_dq0 if age == `num'  & ( college1_dq0 == 1 |  college0_dq1 == 1 )	
	  	matrix b = e(b) 
	  	matrix v = e(V) 
	  	matrix b_se = [ b[1,1] \ ( sqrt(v[1,1]) ) ]
	  	
	  	matrix diff_elife_a`num'   = [nullmat(diff_elife_a`num'), b_se ]	  	
		
	}
		
	matrix diff_elife_a15[1,2] = .
	matrix diff_elife_a15[1,3] = .
	matrix diff_elife_a15[2,2] = .
	matrix diff_elife_a15[2,3] = .
	
   	matrix diff_elife = [diff_elife_a30 \ diff_elife_a15  ]
   
  	matrix colnames diff_elife = "Smoking""Education""Smoking_and_Education"

	matrix rownames diff_elife = "Age_30""Std._Err.""Age_15" "Std._Err." 
	
	matrix list diff_elife
   	outtable using $dir_work_out/stats_elife_effects,         mat(diff_elife) replace          nobox center caption("Average Expected Longevity Difference According to Smoking and Education") f(%100.2f) clabel(stats_elife) 

   	outtable using $dir_tab_out/Table_04,         mat(diff_elife) replace          nobox center caption("Average Expected Longevity Difference According to Smoking and Education") f(%100.2f) clabel(stats_elife) 
